package com.spcloud.guava;

import com.google.common.util.concurrent.RateLimiter;

import java.util.concurrent.TimeUnit;


public class RateLimitDemo {

    public static void main(String[] args) throws Exception {
        RateLimiter rateLimiter = RateLimiter.create(16);
        for (int i = 0; i < 16; i++) {
            TimeUnit.MILLISECONDS.sleep(2);
            double wait = rateLimiter.acquire();
            rateLimiter.tryAcquire();
            System.out.println("wait:" + wait);
//            if (rateLimiter.tryAcquire()) {
//                System.out.println("tryAcquire success---" + i);
//            } else {
//                System.out.println("tryAcquire fail---" + i);
//            }
        }
    }

}
